import _extends from '@babel/runtime/helpers/esm/extends'
import { createNamespace } from '../utils'
import { route, routeProps } from '../utils/router'
import { ChildrenMixin } from '../mixins/relation'
import './style'

var _createNamespace = createNamespace('goods-action-button')
var createComponent = _createNamespace[0]
var bem = _createNamespace[1]

export default createComponent({
  mixins: [ChildrenMixin('emGoodsAction')],
  props: _extends({}, routeProps, {
    type: String,
    text: String,
    icon: String,
    color: String,
    loading: Boolean,
    disabled: Boolean
  }),
  computed: {
    isFirst: function isFirst() {
      var prev = this.parent && this.parent.children[this.index - 1]
      return !prev || prev.$options.name !== this.$options.name
    },
    isLast: function isLast() {
      var next = this.parent && this.parent.children[this.index + 1]
      return !next || next.$options.name !== this.$options.name
    }
  },
  methods: {
    onClick: function onClick(event) {
      this.$emit('click', event)
      route(this.$router, this)
    }
  },
  render: function render() {
    var h = arguments[0]
    return h(
      'el-button',
      {
        class: bem([
          {
            first: this.isFirst,
            last: this.isLast
          },
          this.type
        ]),
        attrs: {
          type: this.type,
          icon: this.icon,
          color: this.color,
          loading: this.loading,
          disabled: this.disabled
        },
        on: {
          click: this.onClick
        }
      },
      [this.slots() || this.text]
    )
  }
})
